package com.incar.chuxing.payment;

import android.app.Activity;
import android.view.View;
import android.widget.Toast;

import com.incar.chuxing.R;
import com.incar.chuxing.api.ApiStore;
import com.incar.chuxing.api.UrlConstant;
import com.incar.chuxing.bean.ChargeResultEvent;
import com.incar.chuxing.bean.DepositCarResultEvent;
import com.incar.chuxing.bean.PaySuccessEvent;
import com.incar.chuxing.bean.WXPreBean;
import com.incar.chuxing.utils.MyApplication;
import com.incar.chuxing.utils.SharedPreferencesKey;
import com.incar.chuxing.utils.SharedPreferencesUtils;
import com.incar.chuxing.utils.ToastUtils;

import org.greenrobot.eventbus.EventBus;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

/**
 * Created by michal on 8/7.
 */
/*
* 统一处理支付的结果
* */
public class PayResult {
    /**
     * @param activity      微信是WXPayEntryActivity  支付宝是发起支付的Activity
     * @param payMethod     1微信  2支付宝 3个人账户
     * @param userPayType   0://缴纳汽车保证金     2://账户充值   3: //汽车订单支付
     * @param payResultCode 0成功  1失败
     */
    public void handlePayResult(Activity activity, int payMethod, int userPayType, int payResultCode) {
        switch (userPayType) {  //判断支付什么
            case 0://缴纳汽车保证金
                EventBus.getDefault().post(new DepositCarResultEvent(payResultCode, payMethod));
             /*   if (payResultCode != 0) {
                    ToastUtils.toast(activity, R.drawable.task_error, "支付失败");
                }*/
                break;
            case 2: //账户充值
                EventBus.getDefault().post(new ChargeResultEvent(payResultCode, payMethod));
               /* if (payResultCode != 0) {
                    ToastUtils.toast(activity, R.drawable.task_error, "支付失败");
                } else {
                    ToastUtils.toast(activity, R.drawable.task_done, "充值成功");
                }*/
                break;
            case 3: //汽车订单支付
                EventBus.getDefault().post(new PaySuccessEvent(payResultCode, payMethod));
               /* if (payResultCode != 0) {
                    ToastUtils.toast(activity, R.drawable.task_error, "支付失败");
                } else {
                    ToastUtils.toast(activity, R.drawable.task_done, "支付成功");
                    SharedPreferencesUtils.getInstance(activity).putIntValue(SharedPreferencesKey.USER_PAY_METHOD, payMethod);     //订单支付后，记录本次的支付方式，
                }*/
                break;
        }

        //微信支付结束EXPayEntryActivity
        if (payMethod == 1) {
            activity.finish();
        }
    }

}
